package com.igelato.controller.User;

import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.igelato.model.User;
import com.igelato.service.UserService;

import com.igelato.response.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description:
 * @Author: wht
 * @Date: 2024-01-24
 */
@Slf4j
@RestController
@RequestMapping("/")
@Api(tags = {"操作" })
public class UserController {
@Autowired
UserService userService;

    @GetMapping("/login")
    public <T> R<T> login(@RequestHeader("X-WX-OPENID") String openid) {
        User user = userService.login(openid);
        return R.successData(user);
    }

    @GetMapping("/getUserInfo")
    public <T> R<T> getUserInfo() {
        User user = userService.getUser();
        return R.successData(user);
    }

    @GetMapping("/savePhoneNumber")
    public <T> R<T> savePhoneNumber(@RequestParam("code") String code) {
        if (code == null || "".equals(code)) {
            throw new RuntimeException();
        }
        String mobile = userService.savePhoneNumber(code);
        return R.successData(mobile);
    }
}
